package smartcarpool.ui;

import android.app.PendingIntent;

import com.example.smartcarpool.R;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

public class tab2_Fragment extends Fragment {

	private EditText pointStartText;
	private EditText dateStartText;
	private EditText timeStartText;
	private EditText pointEndText;
	private EditText dateEndText;
	private EditText timeEndText;
	private FragmentManager fragmentManager;
    private PendingIntent pendIntent;
	private Button findButton;

	private View view;
	public String name = "route";
	
	/*public tab2_Fragment(FragmentManager fm){
		this.fragmentManager = fm;
	}
*/
    public tab2_Fragment(PendingIntent pendingIntent){
        super();
        this.pendIntent = pendingIntent;
    }

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		fragmentManager = getFragmentManager();
		
		view = inflater.inflate(R.layout.tab2_route, container, false);
		Log.d("View ID", view.toString());
		
		pointStartText = (EditText) view.findViewById(R.id.editText1);
		pointEndText = (EditText) view.findViewById(R.id.editText2);
		pointStartText.setText("3379715.40023;8349425.82495"); // long1;lat1 (passenger)
		pointEndText.setText("3381025.63064;8348498.4988");//long2;lat2
		
		timeStartText = (EditText) view.findViewById(R.id.editText4);
		timeEndText = (EditText) view.findViewById(R.id.editText6);
		
		EditTextListenerSC DateTimeListener = new EditTextListenerSC(fragmentManager,view);
		timeStartText.setOnClickListener(DateTimeListener);
		timeEndText.setOnClickListener(DateTimeListener);
		
		dateStartText = (EditText) view.findViewById(R.id.editText3);
		dateEndText = (EditText) view.findViewById(R.id.editText5);
		dateStartText.setOnClickListener(DateTimeListener);
		dateEndText.setOnClickListener(DateTimeListener);
		
		findButton = (Button) view.findViewById(R.id.button1);
		ButtonListenerSC buttonListener = new ButtonListenerSC(fragmentManager, view, pendIntent);
		findButton.setOnClickListener(buttonListener);

        Button showPathButton = (Button) view.findViewById(R.id.button4);
        showPathButton.setOnClickListener(new ButtonListenerSC(fragmentManager, view, pendIntent));
        Button showFellowTravellerButton = (Button) view.findViewById(R.id.button5);
        showFellowTravellerButton.setOnClickListener(new ButtonListenerSC(fragmentManager, view, pendIntent));
		return view;
	}
	
	@Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Log.i("Information", "save bundle");
        outState.putString("startCoord", pointStartText.getText().toString());
        outState.putString("startDate", dateStartText.getText().toString());
        outState.putString("startTime", timeStartText.getText().toString());
        outState.putString("endCoord", pointEndText.getText().toString());
        outState.putString("endDate", dateEndText.getText().toString());
        outState.putString("endTime", timeEndText.getText().toString());
	}

    public void setPendingIntent(PendingIntent pendingIntent){
        this.pendIntent = pendingIntent;
    }
}
